﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Willson.JsbManager.Bll;
using Willson.JsbManager.Comm;
using Willson.JsbManager.BllEntity;

namespace Willson.JsbManager.UI
{
    public partial class XTCompanyBeginJhRegForm : Willson.JsbManager.UI.BaseForm
    {
        private int m_company_id = 0;

        public XTCompanyBeginJhRegForm()
        {
            InitializeComponent();
        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        public override void SelectCompanyId(int id)
        {
            if (id == 0) return;

            this.m_company_id = id;

            this.textBox_company_name.Text = BLLFactory<BLLQuery>.Instance.QueryCompanyInfoByID(this.m_company_id).Name;

            dataGridView.DataSource = BLLFactory<BLLJhBeginReg>.Instance.GetList(this.m_company_id);
        }

        private void bt_query_Click(object sender, EventArgs e)
        {
            SelectCompanyIDForm form = new SelectCompanyIDForm(this);
            form.ShowDialog();
        }

        private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells["id"].Value);
                int begin = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells["jd_jh_begin"].Value);

                if (BLLFactory<BLLJhBeginReg>.Instance.SaveJhBegin(id, begin))
                {
                    MessageUtil.ShowTips("登记成功!");
                }
                else
                {
                    MessageUtil.ShowTips("登记失败!");
                }
            }
            catch
            {
                ;
            }
        }

        private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            int result = 0;

            if (this.dataGridView.Columns[e.ColumnIndex].Name == "jd_jh_begin")
            {
                if (string.IsNullOrEmpty(e.FormattedValue.ToString())) return;
                if (!int.TryParse(e.FormattedValue.ToString(), out result))
                {
                    e.Cancel = true;
                }
            }
        }

        private void XTCompanyBeginJhRegForm_Load(object sender, EventArgs e)
        {
            FunctionName.Text = BLLFactory<BLLMenuInfo>.Instance.GetMenuItemName(info.Menu_id);
        }
     
    }
}
